package service;

import dao.CommentDao;
import entity.Comment;

import java.util.List;

public class CommentService {
    private final CommentDao commentDao = new CommentDao();

    public List<Comment> getCommentsByBlogId(int blogId, String orderBy) {
        return commentDao.getCommentsByBlogId(blogId, orderBy);
    }


    public void addComment(int blogId, int userId, String content) {
        commentDao.addComment(blogId, userId, content);
    }

    public void deleteComment(int commentId, int blogId) {
        commentDao.deleteComment(commentId, blogId);
    }

    public boolean isUserLikeComment(int userId, int commentId) {
        return commentDao.isUserLikedComment(userId, commentId);
    }

    public boolean toggleLikedComment(int userId, int commentId) {
        if(commentDao.isUserLikedComment(userId, commentId)){
            commentDao.unlikeComment(userId, commentId);
            return true;
        }else {
            commentDao.likeComment(userId, commentId);
            return false;
        }
    }
}
